import django_filters
from django.db.models import Q

from goods.models import Product


class MenuFilter(django_filters.rest_framework.FilterSet):
    pid = django_filters.CharFilter(method='pid_filter')

    def pid_filter(self, queryset, name, value):
        # print(type(value), value)
        if value == '0':
            return queryset.filter(level='0')
        return queryset.filter(parentId=value)


class SuperGoodFilter(django_filters.rest_framework.FilterSet):
    """
       商品的过滤类
       """
    title = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Product
        fields = ['title']
